﻿<!DOCTYPE html>
<html>
<head>
  <!-- 页面meta -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>传智健康</title>
  <meta name="description" content="传智健康">
  <meta name="keywords" content="传智健康">
  <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../plugins/elementui/index.css">
  <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="../css/style.css">
  <!-- 引入组件库 -->
  <script type="text/javascript" src="../js/jquery.min.js"></script>
  <script src="../js/vue.js"></script>
  <script src="../plugins/elementui/index.js"></script>
  <script src="../js/axios-0.18.0.js"></script>
  <style>
    .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409EFF;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    .datatable {
      position: relative;
      box-sizing: border-box;
      -webkit-box-flex: 1;
      width: 100%;
      max-width: 100%;
      font-size: 14px;
      color: rgb(96, 98, 102);
      overflow: hidden;
      flex: 1 1 0%;
    }
    .datatable td, .datatable th {
      padding: 12px 0;
      min-width: 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      text-overflow: ellipsis;
      vertical-align: middle;
      position: relative;
      text-align: left;
    }
  </style>
  <script src="../plugins/healthmobile.js"></script>
</head>
<body class="hold-transition">
<div id="app">
  <div class="content-header">
    <h1>会员管理<small>会员档案</small></h1>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>会员管理</el-breadcrumb-item>
      <el-breadcrumb-item>会员档案</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <div class="app-container">
    <div class="box">
      <div class="filter-container">
        <el-input placeholder="姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
        <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
      </div>
      <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
        <el-table-column type="index" align="center" label="序号"></el-table-column>
        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
        <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
        <el-table-column label="性别" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证" align="center"></el-table-column>
        <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
        <el-table-column prop="birthday" label="生日" align="center"></el-table-column>
        <el-table-column prop="regTime" label="注册时间" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button  type="primary" size="mini" @click="handleUpdate(scope.row)" >编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
      </div>
      <!-- 添加标签弹层-->
      <div class="add-form">
        <el-dialog title="添加会员档案" :visible.sync="dialogFormVisible">
          <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
            <el-row>
              <el-col :span="11">
                <el-form-item label="档案号" prop="fileNumber">
                  <el-input v-model="formData.fileNumber" maxlength="15"/>
                </el-form-item>
              </el-col>
              <el-col :span="11">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="formData.name"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="性别" prop="sex">
                  <el-select v-model="formData.sex">
                    <el-option label="不限" value="0"></el-option>
                    <el-option label="男" value="1"></el-option>
                    <el-option label="女" value="2"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="生日" prop="birthday">
                  <el-date-picker
                          v-model="formData.birthday"
                          type="date"
                          placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="手机号" prop="phoneNumber">
                  <el-input v-model="formData.phoneNumber" maxlength="11"/>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="formData.email"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="身份证" prop="idCard">
                  <el-input v-model="formData.idCard" maxlength="18"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <el-button @click="resetForm('dataAddForm')">重置</el-button>
            <el-button type="primary" @click="handleAdd()">确定</el-button>
          </div>
        </el-dialog>
      </div>
      <!-- 编辑标签弹层 -->
      <div class="add-form">
        <el-dialog title="编辑会员档案" :visible.sync="dialogFormVisible4Edit">
          <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
            <el-row>
              <el-col :span="11">
                <el-form-item label="档案号" prop="fileNumber">
                  <el-input v-model="formData.fileNumber" disabled/>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="formData.name"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="性别" prop="sex">
                  <el-select v-model="formData.sex">
                    <el-option label="不限" value="0"></el-option>
                    <el-option label="男" value="1"></el-option>
                    <el-option label="女" value="2"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="12" >
                <el-form-item label="生日" prop="birthday">
                  <el-date-picker
                          v-model="formData.birthday"
                          type="date"
                          placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="18">
                <el-form-item label="身份证" prop="idCard">
                  <el-input v-model="formData.idCard" maxlength="18"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="手机号" prop="phoneNumber">
                  <el-input v-model="formData.phoneNumber" maxlength="11"/>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="formData.email"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="注册时间">
                  <el-input v-model="formData.regTime" disabled/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
            <el-button type="primary" @click="handleEdit()">确定</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</div>
</body>
<script src="../plugins/healthmobile.js"></script>
<script>

    var Main = {
        data() {
            //唯一性验证 手机号 邮箱 档案号 身份证号
            let phoneValidate = (rule, value, callback) => {
                //通过axios查询后台数据
                axios.post('/member/phoneValidator.do',this.formData).then((res) => {
                    /*console.log(res.data);
                    console.log(this.formData);*/
                    if(res.data === '手机号已经存在'){
                        return callback(new Error('手机号已经存在'));
                    }else{
                        callback();
                    }
                })
            }
            let fileNumberValidate = (rule, value, callback) => {
                //通过axios查询后台数据
                axios.post('/member/fileNumberValidator.do',this.formData).then((res) => {
                    /*console.log(res.data)*/
                    if(res.data === '档案号已经存在'){
                        return callback(new Error('档案号已经存在'));
                    }else {
                        callback();
                    }
                })
            };
            let idCardValidate = (rule, value, callback) => {
                //通过axios查询后台数据
                axios.post('/member/idCardValidator.do',this.formData).then((res) => {
                    /*console.log(res.data)*/
                    if(res.data === '身份证已经存在'){
                        return callback(new Error('身份证已经存在'));
                    }else {
                        callback();
                    }
                })
            }
            let emailValidate = (rule, value, callback) => {
                //通过axios查询后台数据
                axios.post('/member/emailValidator.do',this.formData).then((res) => {
                    /*console.log(res.data)*/
                    if(res.data === '邮箱已经存在'){
                        return callback(new Error('邮箱已经存在'));
                    }else {
                        callback();
                    }
                })
            }
            return {
                pagination: {//分页相关属性
                    currentPage: 1,  //当前页
                    pageSize:10,  //一页显示的数量
                    total:100,  //总数
                    queryString:null
                },
                dataList: [],//列表数据
                formData: {
                    sex : '不限'
                },//表单数据
                tableData:[],//添加表单窗口中检查组列表数据
                dialogFormVisible: false,//控制增加窗口显示/隐藏
                dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
                dataAddForm: {
                    name: '',
                    phoneNumber: '',
                    fileNumber: '',
                    idCard: '',
                    email: '',
                    sex: [],
                    birthday: ''
                },
                dataEditForm: {
                    name: '',
                    phoneNumber: '',
                    idCard: '',
                    email: '',
                    sex: [],
                },
                rules: {//校验规则
                    //姓名验证
                    name: [{required: true, message: '姓名为必填项', trigger: 'blur' },
                        {pattern:/^[\u4E00-\u9FA5]{2,4}$/,message:'您的姓名有点小别致哦(#^.^#)'}],
                    //手机号验证
                    phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'},
                        {pattern:/^[1][3,4,5,7,8][0-9]{9}$/,message:'手机号格式错误',trigger: 'blur'},
                        {validator:phoneValidate, trigger: 'blur'}
                    ],
                    //档案号验证
                    fileNumber:[{required: true, message: '档案号为必填项', trigger: 'blur'},
                        {pattern:/^\d{11}|\d{15}$/,message:'档案号只能是数字并且不能少于11位多于15位',trigger: 'blur'},
                        {validator:fileNumberValidate, trigger: 'blur'}],
                    //身份证验证
                    idCard:[{required: true, message: '身份证为必填项', trigger: 'blur'},
                        {pattern:/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i,message:'身份证格式错误了,您应该不是外星人吧',trigger: 'blur'},
                        {validator:idCardValidate, trigger: 'blur'}],
                    //邮箱验证
                    email:[{required: true, message: '邮箱为必填项', trigger: 'blur'},
                        {pattern:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,message:'邮箱格式不对',trigger: 'blur'},
                        {validator:emailValidate, trigger: 'blur'}],
                    //性别验证
                    sex:[{required: true, message: '请选择性别', trigger: 'change'}],
                    //日期验证
                    birthday:[{required: true, message: '请选择生日', trigger: 'change'}]
                },
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //VUE日期转换
            dateFormat:function(time) {
                var date=new Date(time);
                var year=date.getFullYear();
                /* 在日期格式中，月份是从0开始的，因此要加0
                 * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
                 * */
                var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
                var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
                // 拼接
                return year+"-"+month+"-"+day;
            },
            //弹出添加页面
            handleCreate(){
                this.resetForm('dataAddForm');
                this.dialogFormVisible = true;
            },
            //添加
            handleAdd(row){
                this.$refs['dataAddForm'].validate((valid) => {
                    if(valid){
                        axios.post('/member/add.do',this.formData).then((res) => {
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                this.dialogFormVisible = false;
                                //计算最后一页
                                var page = 0;
                                if(this.pagination.total % this.pagination.pageSize == 0){
                                    page = this.pagination.total / this.pagination.pageSize;
                                }else {
                                    page = (this.pagination.total / this.pagination.pageSize)+1;
                                }
                                //跳转到最后一页
                                this.handleCurrentChange(page);
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                    }else{
                        //校验不通过，提示错误信息1
                        this.$message.error("表单数据校验失败，请检查输入是否正确！");
                    }
                });
            },
            //弹出编辑页面
            handleUpdate(row){
                this.resetForm('dataEditForm');
                this.dialogFormVisible4Edit = true;
                axios.get('/member/findById.do?id='+row.id).then((res) => {
                    if(res.data.flag){
                        res.data.data.regTime = this.dateFormat(res.data.data.regTime);
                        this.formData = res.data.data;
                    }else {
                        this.$message.error(res.data.message);
                    }
                })
            },
            //编辑
            handleEdit(){
                this.$refs['dataEditForm'].validate((valid) => {
                    if(valid){
                        axios.post('/member/edit.do',this.formData).then((res) => {
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                this.dialogFormVisible4Edit = false;
                                this.findPage();
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                    }else{
                        //校验不通过，提示错误信息
                        this.$message.error("表单数据校验失败，请检查输入是否正确！");
                    }
                });
            },
            //分页查询
            findPage(currentPage) {
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };
                this.pagination.currentPage = currentPage;//指定最新的页码
                //发送ajax请求，进行分页查询
                axios.post("/member/findPage.do",param).then((res) => {
                    this.pagination.total = res.data.total;
                    /*循环更改日期格式*/
                    for (i in res.data.rows) {
                        res.data.rows[i].regTime=this.dateFormat(res.data.rows[i].regTime);
                        res.data.rows[i].birthday=this.dateFormat(res.data.rows[i].birthday);
                    }
                    this.dataList = res.data.rows;

                });
            },
            // 重置表单
            resetForm(formName) {
                this.formData = {};
                if (this.$refs[formName]!==undefined) {
                    this.$refs[formName].resetFields()
                }
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;//指定最新的页码
                this.findPage();
            }
        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')

</script>
</html>
